#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=1e6+1000;
const int mod=1000000007;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
char str[maxn];
LL d[maxn],n,dp[maxn];
inline void pre(){
    int i=1;int j=0;
    while(i<n){
        if(str[i]==str[j]){
            dp[i]=dp[d[i-1]]+1;
            d[i++]=++j;
            continue;
        }
        else{
            if(j) j=d[j-1];
            else{
                dp[i]=dp[d[i-1]]+1;
                i++;
            }
        }
    }
//    for(int i=0;i<n;i++){
//        cout<<dp[i]<<" ";
//    }cout<<endl;
}
inline LL solve(){
    memset(d,0,n*sizeof(LL));
    memset(dp,0,n*sizeof(LL));
    n=strlen(str);
    pre();
    LL res=1;
    LL i=1;LL j=0;
    while(i<n){
        //bool flag=false;
        if(str[i]==str[j]){
            i++;j++;
        }
        else{
            if(j) {j=d[j-1];continue;}
            else i++;
        }
        while(j*2>i) j=d[j-1];
        res=(res*(dp[j]+1))%mod;
        ///if(flag) i++;
    }
    return res;
}
int main(void){
   	 cin.tie(0);std::ios::sync_with_stdio(false);
     LL t;cin>>t;
     while(t--){
        cin>>str;
        LL ans=solve();
        cout<<ans<<endl;
     }
   	return 0;
}
